<!DOCTYPE html>
<html lang="en"  xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

  <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Pet Homepage</title>

    <link th:href="@{/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/home.css}" rel="stylesheet">

  </head>

  <body>

    <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
      <div class="container">
        <a class="navbar-brand" href="#">Pet Platform</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarResponsive">
          <ul class="navbar-nav ml-auto">
            <li class="nav-item ">
              <a class="nav-link" href="/index">Home

              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="/api/orders">Orders</a>
            </li>
            <li class="nav-item active">
              <a class="nav-link" href="/activities">Activities<span class="sr-only">(current)</span></a>
            </li>

            <li class="nav-item" th:if="${#strings.isEmpty(session.email)}">
              <a class="nav-link" href="/login">Signin</a>
            </li>

            <li class="nav-item dropdown" th:if="${not #strings.isEmpty(session.email)}">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span th:text="${session.email}">...</span>
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                <a class="dropdown-item" href="/logout">Logout</a>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </nav>

    <div class="container">

      <div class="row">

        <div class="col-lg-12" style="margin-top: 50px">

          <div class="row">

            <div class="col-lg-4 col-md-6 mb-4" th:each="activity : ${activities}">
              <div class="card h-100">
                <img class="card-img-top" th:src="@{'/uploadfile/'+${activity.pic}}" alt="">
                <div class="card-body">
                  <h4 class="card-title"  th:text="${activity.title}">
                  </h4>
                  <h5 class="card-title"  th:text="@{${activity.location} +' , '+${#dates.format(activity.acttime,'yyyy-MM-dd HH:mm')}}">
                  </h5>
                  <p class="card-text" th:text="${activity.desctxt}"></p>
                  <input type="hidden" name="actId" th:value="${activity.id}" />
                  <button class="enroll btn btn-primary" data-toggle="modal" data-target="#myModal">Enroll</button>
                </div>

              </div>
            </div>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <h4 class="modal-title" id="myLabel">Enroll Activity</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                  </div>
                  <form action="/api/enroll" method="POST">
                    <div class="modal-body">
                      <input type="hidden" name="actId" id="actId"/>
                      <input type="text" class="form-control" name="name" id="name" placeholder="name">
                      <br>
                      <input type="text" class="form-control" name="phone" id="phone" placeholder="phone">
                      <br>
                      <input type="text" class="form-control" name="address" id="address" placeholder="address">
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                      <button type="submit" class="btn btn-primary" id="confirm_add">Confirm</button>
                    </div>
                  </form>
                </div>
              </div>
            </div>

          </div>
          <!-- /.row -->

        </div>
        <!-- /.col-lg-9 -->

      </div>
      <!-- /.row -->

    </div>
    <!-- /.container -->

    <!-- Footer -->
    <footer class="py-5 bg-dark">
      <div class="container">
        <p class="m-0 text-center text-white">Copyright &copy; Pet Platform 2018</p>
      </div>
      <!-- /.container -->
    </footer>

    <!-- Bootstrap core JavaScript -->
    <script th:src="@{/jquery/jquery.min.js}"></script>
    <script th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <script th:inline="javascript">

        $(".enroll").click(function(event){
            var id = $(event.target).prev().val();
            $("#actId").val(id);
        });


    </script>
  </body>

</html>
